/*
 * @lc app=leetcode.cn id=83 lang=cpp
 *
 * [83] 删除排序链表中的重复元素
 */

// @lc code=start
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head) {
        ListNode* p = head;
        while (p != NULL && p->next != NULL)
        {
            if(p->next->val == p->val)
            {
                delNext(p);
            }
            else
            {
                p = p->next;
            }
            
        }
       return head; 
    }
    inline void delNext(ListNode* p)
    {
        ListNode* tmp = p->next;
        p->next = p->next->next;
        delete(tmp);
    }
};
// @lc code=end

